cmake_minimum_required(VERSION 3.10)

set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(QT NAMES Qt6 COMPONENTS Core Widgets Network REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Widgets  Network REQUIRED)
find_package(QT NAMES Qt6 COMPONENTS Charts)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Charts)
find_package(QT NAMES Qt6 COMPONENTS Graphs QuickWidgets Quick)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Graphs QuickWidgets Quick)

#get_cmake_property(_variableNames VARIABLES)
#foreach (_variableName ${_variableNames})
#    message(STATUS "${_variableName}=${${_variableName}}")
#endforeach()

include_directories(${TASKBUS_INTERFACEDIR})

# 确认有没有 charts 或者 graphs 库，没有的话，就不显示折线图了。
if (Qt${QT_VERSION_MAJOR}Charts_FOUND)
	message("Charts found.")
	set(PRJ_GUISTATUS
	watchdog/status_charts/formstatus.h
	watchdog/status_charts/formstatus.cpp
	watchdog/status_charts/formstatus.ui
	)
	include_directories(watchdog/status_charts)
	set(TB_CHARTS_LIB
	Qt${QT_VERSION_MAJOR}::Charts
	)
elseif (Qt${QT_VERSION_MAJOR}Graphs_FOUND)
	message("Graphs found.")
	set(PRJ_GUISTATUS
	watchdog/status_graphs/formstatus.h
	watchdog/status_graphs/formstatus.cpp
	watchdog/status_graphs/formstatus.ui
	)
	include_directories(watchdog/status_graphs)
	set(TB_CHARTS_LIB
	Qt${QT_VERSION_MAJOR}::Graphs Qt${QT_VERSION_MAJOR}::QuickWidgets Qt${QT_VERSION_MAJOR}::Quick
	)
else()
	set(PRJ_GUISTATUS
	watchdog/status_nocharts/formstatus.h
	watchdog/status_nocharts/formstatus.cpp
	watchdog/status_nocharts/formstatus.ui
	)
	include_directories(watchdog/status_nocharts)
	set(TB_CHARTS_LIB
	)
endif()

set(PRJ_HEADERS_CORE
	core/tasknode.h
	core/taskcell.h
	core/taskproject.h
	core/process_prctl.h
	../tb_interface/cmdlineparser.h
	../tb_interface/tb_interface.h
	watchdog/tbwatchdog.h
	watchdog/profile_log.h
)
set(PRJ_HEADERS_GUI
	gui/taskbusplatformfrm.h
	gui/handbookview.h
	gui/pdesignerview.h
	gui/taskmodule.h
	gui/tgraphicstaskitem.h
	gui/dlgabout.h
	gui/tbscene.h
	gui/dlgsettings.h
)
set(PRJ_SOURCES_CORE
	core/tasknode.cpp
	core/taskcell.cpp
	core/taskproject.cpp
	core/process_prctl.cpp
	watchdog/tbwatchdog.cpp
	watchdog/watchmemmodule.cpp
)
set(PRJ_SOURCES_GUI
	gui/taskbusplatformfrm.cpp
	gui/taskbusplatformfrm_modules.cpp
	gui/taskbusplatformfrm_project.cpp
	gui/dlgabout.cpp
	gui/pdesignerview.cpp
	gui/handbookview.cpp
	gui/taskmodule.cpp
	gui/tgraphicstaskitem.cpp
	gui/custom_item_editor.cpp
	gui/tbscene.cpp
	gui/dlgsettings.cpp
)
set(PRJ_FORMS
	gui/taskbusplatformfrm.ui
	gui/handbookview.ui
	gui/pdesignerview.ui
	gui/dlgabout.ui
	gui/dlgsettings.ui
)

set(PRJ_RESOURCES
	taskbusplatform.qrc
	taskBusPlatform_zh_CN.ts
	taskbusplatform.rc
)

# ========================GUI Exe========================
qt_add_executable(taskBusPlatform
	MANUAL_FINALIZATION
	gui/main.cpp
	${PRJ_HEADERS_CORE}
	${PRJ_HEADERS_GUI}
	${PRJ_SOURCES_CORE}
	${PRJ_SOURCES_GUI}
	${PRJ_FORMS}
	${PRJ_RESOURCES}
	${PRJ_GUISTATUS}
)

target_link_libraries(taskBusPlatform PRIVATE
	Qt${QT_VERSION_MAJOR}::Widgets
	Qt${QT_VERSION_MAJOR}::Network
	${TB_CHARTS_LIB}
	${TBLinkExtra}
)

set_target_properties(taskBusPlatform PROPERTIES
	MACOSX_BUNDLE_GUI_IDENTIFIER taskBus.taskBusPlatform
	MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
	MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
	MACOSX_BUNDLE TRUE
	WIN32_EXECUTABLE TRUE
)

qt_finalize_executable(taskBusPlatform)


# ========================TUI Exe========================

add_executable(taskBusConsole
	tui/listen_thread.h
	tui/taskbus_console.cpp
	tui/listen_thread.cpp
	${PRJ_HEADERS_CORE}
	${PRJ_SOURCES_CORE}
)


target_link_libraries(taskBusConsole
	Qt${QT_VERSION_MAJOR}::Core
	${TBLinkExtra}
)

# ====copy doc
add_custom_command(TARGET taskBusPlatform
		 POST_BUILD
		 COMMAND echo Copy Handbook to EXE path
		 COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/../documents ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/taskBusPlatform.handbook
	 )

